<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分页练习</title>
    <style>
        * {margin: 0; padding: 0; color: #777;font-size: 14px; }
        body {font-family: "Microsoft YaHei";}
        table {
            border: 1px solid #d1d1d1;
            border-collapse: collapse;
            width: 80%;
            margin: 0 auto;
        }
        table tr {
            height: 45px;
        }
        table tr td, table tr th {
            text-align: center;
            border: 1px solid #d1d1d1;
        }
        table tr th {
            font-size: 16px;
            color: #222;
        }
        .pagination {
            min-width: 300px;
            max-width: 650px;
            height: 45px;
            line-height: 45px;
            margin: 20px auto;
        }
        .pagination ul {
            list-style: none;
        }
        .pagination ul li {
            float:left;
            margin-left: 8px;
        }
        .pagination ul li a {
            display: block;
            width:30px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            text-decoration: none;
            background: #5fa5f8;
            color: #fff;
            border-radius: 2px;
        }
        .pagination ul li a.next {
            width: 120px;
        }
        .pagination ul li a:hover {
            background: #66c7ff;
        }
        .pagination ul li a.curr {
            background: #55d7ff;
        }
    </style>
</head>
<body>
  <div>
      <table>
          <tr>
              <th>id</th>
              <th>用户名</th>
              <th>内容</th>
              <th>留言时间</th>
              <th>like</th>
          </tr>
          <?php foreach ($messages as $m): ?>
              <tr>
                  <td><?php echo $m->id ?></td>
                  <td><?php echo $m->user_name ?></td>
                  <td><?php echo $m->content ?></td>
                  <td><?php echo $m->created_at ?></td>
                  <td><?php echo $m->like_num ?></td>
              </tr>
          <?php endforeach; ?>
      </table>
  </div>
  <div class="pagination">
      <ul>
          <li>
              <?php if ($pn - 1 >= 0)?>
              <a href="?pn=<?php echo $pn - 1 ?>" class="next">上一页</a>
              <?php endif;?>
          </li>
          <?php for($i = 1; $i <= $pageCount; $i++): ?>
          <li>
              <?php if($i == $pn): ?>
              <a class="curr" href="?pn=<?php echo $i ?>">
              <?php else: ?>
              <a href="?pn=<?php echo $i ?>">
              <?php endif; ?>
              <?php echo $i ?></a>
          </li>
          <?php endfor; ?>
          <li>
              <a href="?pn=<?php echo $pn + 1; ?>" class="next">下一页</a>
          </li>
      </ul>
  </div>
</body>
</html>